package com.example.talkheart.adapter

import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.talkheart.AppointInfoActivity
import com.example.talkheart.MyApplication
import com.example.talkheart.R
import com.example.talkheart.TeacherActivity
import com.example.talkheart.entity.TeacherBean

class AppointAdapter(teacherActivity: TeacherActivity) : RecyclerView.Adapter<TeacherAdapter.TeacherViewHolder>() {
    private var dataList : List<TeacherBean> = listOf(
        TeacherBean(1,"李华","4-18 15:00-16:00"),
        TeacherBean(2,"李梅","4.19 17:00-18:00")
    )
    private val activity = teacherActivity

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): TeacherAdapter.TeacherViewHolder {
        val view = LayoutInflater.from(MyApplication.context).inflate(R.layout.teacher_item,parent,false)
        return TeacherAdapter.TeacherViewHolder(view)
    }

    override fun onBindViewHolder(holder: TeacherAdapter.TeacherViewHolder, position: Int) {
        holder.teacherName.text = dataList.get(position).name
        holder.helpTime.text = dataList.get(position).time
        holder.appointCheckBox.visibility = View.INVISIBLE

        holder.teacherName.setOnClickListener{
            val intent = Intent(MyApplication.context,AppointInfoActivity::class.java)
            intent.putExtra("name",holder.teacherName.text)
            intent.putExtra("time",holder.helpTime.text)
            activity.turnIntoAppointInfoActivity(intent)
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}